#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
int main()
{
  //写文件
  umask(0);
  int fd = open("text.txt",O_RDWR | O_CREAT | O_TRUNC,0777);
  char* buff = "hello linux\nhello c++";
  write(fd,buff,strlen(buff));
  //close(fd);
  
  //读文件
  //fd = open("text.txt",O_RDONLY);
  lseek(fd,0,SEEK_SET);
  char buffer[1024] = {0};
  int ret = read(fd,buffer,strlen(buff));
  if(ret == -1)
  {
    perror("read");
    return 1;
  }
  printf("%s\n",buffer);
  close(fd);
  return 0;
}
